package com.mall.controller;

import com.mall.domain.dto.ReviewDTO;
import com.mall.domain.vo.ReviewVO;
import com.mall.result.Result;
import com.mall.service.ReviewService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @description: 评论控制器
 * @author 勾新杰
 * @version 1.0
 * @date 2024/11/27 19:49
 */
@RestController
@RequestMapping("/review")
@RequiredArgsConstructor
@Tag(name = "评论管理", description = "评论控制器")
public class ReviewController {

    private final ReviewService reviewService;

    /**
     * 添加评论
     * @param reviewDTO 评论DTO
     * @return 添加成功
     */
    @PostMapping("/addReview")
    @Operation(summary = "添加评论")
    public Result<String> addReview(@RequestBody ReviewDTO reviewDTO){
        reviewService.addReview(reviewDTO);
        return Result.success("添加成功");
    }

    /**
     * 获取某个商品的评论列表
     * @return 评论列表
     */
    @GetMapping("/list/{itemId}")
    @Operation(summary = "获取某个商品评论列表")
    public Result<List<ReviewVO>> list(@PathVariable Long itemId){
        List<ReviewVO> reviewVOList = reviewService.list(itemId);
        return Result.success(reviewVOList);
    }

    /**
     * 根据id获取评论
     * @param id 评论id
     * @return 评论
     */
    @GetMapping("/{id}")
    @Operation(summary = "根据id获取评论")
    public Result<ReviewVO> getById(@PathVariable Long id){
        ReviewVO reviewVO = reviewService.getById(id);
        return Result.success(reviewVO);
    }

    /**
      * 根据id删除评论
      * @param id 评论id
      * @return 删除成功
      */
    @DeleteMapping("/delete/{id}")
    @Operation(summary = "删除评论")
    public Result<String> deleteById(@PathVariable Long id){
        reviewService.deleteById(id);
        return Result.success("删除成功");
    }
}
